package com.atstudy.exception;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/22 9:38
 * @copyright: 博为峰
 */
public class ExceptionDemo02 {
    public static void main(String[] args) throws MyException{
        int[] arr = new int[5];
//        System.out.println(arr[5]);
//        arr = null;
//        System.out.println(arr[0]);
        m1(arr, -5);
    }

    public static void m1(int[] arr, int index) throws MyException {
        if (arr == null) {
            throw new NullPointerException("空指针异常");
        }
        if (index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("下标越界异常");
        }

        if (index < 0) {
//            throw new MyException("下标不能是负值");//编译时异常
        }
        System.out.println(arr[index]);
    }
}
